package com.example.demo.controller;


import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.demo.exception.bizException.BizException;
import com.example.demo.entity.dto.ResultBean;
import com.example.demo.service.PPhotoService;
import com.example.demo.entity.PPhoto;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cy
 * @since 2020-10-09
 * @version v1.0
 */
@RestController
@RequestMapping("/p-photo")
public class PPhotoController {

    @Autowired
    private PPhotoService pPhotoService;

    /**
    * 查询分页数据
    */
    @RequestMapping(method = RequestMethod.GET)
    public ResultBean<?> listByPage(@RequestParam(name = "page", defaultValue = "1") int page,
                                    @RequestParam(name = "pageSize", defaultValue = "10") int pageSize,
                                    @RequestParam(name = "factor", defaultValue = "") String factor) {
        return new ResultBean<>(pPhotoService.listPPhotosByPage(page, pageSize,factor));
    }


    /**
    * 根据id查询
    */
    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    public ResultBean<?> getById(@PathVariable("id") Integer id) {
        return new ResultBean<>(pPhotoService.getPPhotoById(id));
    }


    /**
     * 根据专利id查询
     */
    @RequestMapping(method = RequestMethod.GET, value = "/normal/patent/{id}")
    public ResultBean<?> getByDid(@PathVariable("id") Integer id) {
        return new ResultBean<>(pPhotoService.getPPhotoByPId(id));
    }

    /**
    * 新增
    */
    @RequestMapping(method = RequestMethod.POST)
    public ResultBean<?> insert(@RequestBody PPhoto pPhoto) {
        return new ResultBean<>(pPhotoService.insertPPhoto(pPhoto));
    }

    /**
    * 删除
    */
    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    public ResultBean<?> deleteById(@PathVariable("id") Integer id) {
        return new ResultBean<>(pPhotoService.deletePPhotoById(id));
    }

    /**
    * 修改
    */
    @RequestMapping(method = RequestMethod.PUT)
    public ResultBean<?> updateById(@RequestBody PPhoto pPhoto) {
        return new ResultBean<>(pPhotoService.updatePPhoto(pPhoto));
    }
}
